package com.voltmaon.shortlink.jpa;

import java.io.Serializable;
import javax.persistence.*;


import org.hibernate.annotations.GenericGenerator;
import org.joda.time.DateTime;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.voltmaon.shortlink.converter.DateTimeConverter;
import com.voltmaon.shortlink.converter.JsonJodaDateTimeSerializer;


/**
 * @author lfj
 */
@lombok.Getter
@lombok.Setter
@lombok.NoArgsConstructor
@Entity
@Table(name = "short_link_info")
public class ShortLink implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GenericGenerator(
		name = "info_generator",
		strategy = "org.hibernate.id.enhanced.TableGenerator",
		parameters = {@org.hibernate.annotations.Parameter(
			name = "table_name",
			value = "hibernate_sequence"
		), @org.hibernate.annotations.Parameter(
			name = "segment_column_name",
			value = "sequence_name"
		), @org.hibernate.annotations.Parameter(
			name = "value_column_name",
			value = "next_val"
		), @org.hibernate.annotations.Parameter(
			name = "increment_size",
			value = "1"
		), @org.hibernate.annotations.Parameter(
			name = "optimizer",
			value = "pooled-lo"
		), @org.hibernate.annotations.Parameter(
			name = "prefer_entity_table_as_segment_value",
			value = "true"
		)}
	)
	@GeneratedValue(
		generator = "info_generator"
	)
	private Long id;

	/**
	 * 认证码
	 */
	private String authCode;

	/**
	 * 短链接失效日期
	 */
	@JsonSerialize(using = JsonJodaDateTimeSerializer.class)
	@Convert(converter = DateTimeConverter.class)
	private DateTime deadline;

	/**
	 * 完整链接
	 */
	private String fullLink;
	/**
	 * 短链接
	 */
	private String shortLink;
	/**
	 * 失效跳转链接
	 */
	private String expiresLink;
	/**
	 * 认证失败跳转链接
	 */
	private String authFaildLink;
}